class EatMan{
    constructor(name){
        this.timer=null
        this.hasHightLevelTask=false
        this.callbacks=[]
        this.printName(name)
    }
    tick(){
       clearTimeout(this.timer)
       this.timer=setTimeout(() => {
           for (let i=0;i<this.callbacks.length;i++){
              this.callbacks[i]() 
           }
           
       }, 0);
    }
    printName(name){
        this.callbacks.push(()=>{console.log(`hi,this is ${name}`)})
        if(!this.hasHightLevelTask){
            this.tick()
        }
        return this
    }
    eat(name){
        this.callbacks.push(()=>{console.log(`Eat ${name}`)})
        if(!this.hasHightLevelTask){
            this.tick()
        }
        return this
    }

    awaitFirst(s){
        clearTimeout(this.timer)
        this.hasHightLevelTask=true
        this.callbacks.unshift(()=>{console.log(`await first`)})
        this.timer=setTimeout(() => {
            for (let i=0;i<this.callbacks.length;i++){
                this.callbacks[i]() 
             }    
        }, s*1000);
        return this
    }
}
new EatMan('Luo').eat('晚餐').awaitFirst(5).eat('最后一餐')